/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author new
 */
public class MnemonicHandler {

    public MnemonicHandler() throws FileNotFoundException, IOException{
        getTable();
    }

    public String toHex(String mnemonic){
        Pattern pattern;
        Matcher matcher;
        String result = new String(mnemonic);
        boolean hasFind = false;
        int hasFindIndex = 0;
        for(int i = 0; i< 256; i++){
            pattern = Pattern.compile(mnemonicTable[i][3],Pattern.CASE_INSENSITIVE);
            matcher =pattern.matcher(result);
            if(matcher.find()){
                if(hasFind){
                    System.out.println("Can't write two mnemonic in one line.");
                    System.exit(0);
                }
                hasFind = true;
                hasFindIndex = i;
            }
            result = matcher.replaceAll(mnemonicTable[i][1]);
        }

        pattern = Pattern.compile("(\\s*,\\s*\\bA\\b\\s*)|(\\s*,\\s*)",Pattern.CASE_INSENSITIVE);
        matcher = pattern.matcher(result);
        result = matcher.replaceAll("");
        if(!hasFind){
            System.out.println(mnemonic + "not a legal mnemonic!");
            System.exit(0);
        }
        if(mnemonicTable[hasFindIndex][4].equals("3")){
            if(Integer.valueOf(result, 16) < 65536){
                result = result.substring(0, 2) + "00" + result.substring(2);
            }
        }
        if(!mnemonicTable[hasFindIndex][4].equals("" + result.length()/2)){
            System.out.println(mnemonic + " error!");
            System.exit(0);
        }

        return result;
    }

    public int countLength(String in){
        int length = 0;
        String temp = new String(in);
        Pattern pattern;
        Matcher matcher;
        boolean hasFind = false;

        for(int i = 0; i< 256; i++){
            pattern = Pattern.compile(mnemonicTable[i][3],Pattern.CASE_INSENSITIVE);
            matcher =pattern.matcher(temp);
            if(matcher.find()){
                if(hasFind){
                    System.out.println("Can't write two mnemonic in one line.");
                    System.exit(0);
                }
                hasFind = true;
                length += Integer.valueOf(mnemonicTable[i][4], 10);
            }
            
        }

        return length;
    }

    private void getTable() throws FileNotFoundException, IOException {
//        File f = new File("MnemonicToHexTable.txt");
//        if(!f.exists()){
//            System.err.println("MnemonicToHexTable.txt not exists.");
//        }
//        BufferedReader br = new BufferedReader(new FileReader(f));
//
//        String tempStr = br.readLine();
//        int i = 0;
//
//        while(tempStr != null){
//            mnemonicTable[i] = tempStr.split(" ");
//            i++;
//            tempStr = br.readLine();
//        }
//
//        br.close();
        mnemonicTable[0] = "0 00 00000000 \\bNOP\\b 1".split(" ");
        mnemonicTable[1] = "1 01 00000001 \\breserved\\b 0".split(" ");
        mnemonicTable[2] = "2 02 00000010 \\breserved\\b 0".split(" ");
        mnemonicTable[3] = "3 03 00000011 \\breserved\\b 0".split(" ");
        mnemonicTable[4] = "4 04 00000100 \\breserved\\b 0".split(" ");
        mnemonicTable[5] = "5 05 00000101 \\breserved\\b 0".split(" ");
        mnemonicTable[6] = "6 06 00000110 \\breserved\\b 0".split(" ");
        mnemonicTable[7] = "7 07 00000111 \\breserved\\b 0".split(" ");
        mnemonicTable[8] = "8 08 00001000 \\bSET\\b\\s+\\bC\\b 1".split(" ");
        mnemonicTable[9] = "9 09 00001001 \\bCLR\\b\\s+\\bC\\b 1".split(" ");
        mnemonicTable[10] = "10 0A 00001010 \\bSET\\b\\s+\\bBS\\b 1".split(" ");
        mnemonicTable[11] = "11 0B 00001011 \\bCLR\\b\\s+\\bBS\\b 1".split(" ");
        mnemonicTable[12] = "12 0C 00001100 \\bSET\\b\\s+\\bIE\\b 1".split(" ");
        mnemonicTable[13] = "13 0D 00001101 \\bCLR\\b\\s+\\bIE\\b 1".split(" ");
        mnemonicTable[14] = "14 0E 00001110 \\bCPL\\b\\s+\\bC\\b 1".split(" ");
        mnemonicTable[15] = "15 0F 00001111 \\bCPL\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[16] = "16 10 00010000 \\bXCSD\\b 1".split(" ");
        mnemonicTable[17] = "17 11 00010001 \\bSFA\\b 1".split(" ");
        mnemonicTable[18] = "18 12 00010010 \\bLAF\\b 1".split(" ");
        mnemonicTable[19] = "19 13 00010011 \\bMOV\\b\\s+\\bDPTR\\b\\s*,\\s*\\bSP\\b 1".split(" ");
        mnemonicTable[20] = "20 14 00010100 \\bMOV\\b\\s+\\bSP\\b\\s*,\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[21] = "21 15 00010101 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[22] = "22 16 00010110 \\bMOV\\b\\s+\\bSP\\b\\s*,\\s*#\\s* 3".split(" ");
        mnemonicTable[23] = "23 17 00010111 \\bMOV\\b\\s+\\bDPTR\\b\\s*,\\s*#\\s* 3".split(" ");
        mnemonicTable[24] = "24 18 00011000 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*(?!(\\s*(@|#|(\\bR0\\b)|(\\bR1\\b)|(\\bR2\\b)|(\\bR3\\b)|(\\bDPH\\b)|(\\bDPL\\b)|(\\bSPH\\b)|(\\bSPL\\b)))) 3".split(" ");
        mnemonicTable[25] = "25 19 00011001 \\bMOV\\b\\s+(?=\\w*,\\s*\\bA\\b)(?!\\bR0\\b|\\bR1\\b|\\bR2\\b|\\bR3\\b|\\bDPH\\b|\\bDPL\\b|\\bSPH\\b|\\bSPL\\b) 3".split(" ");
        mnemonicTable[26] = "26 1A 00011010 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bA\\b\\s*\\b\\+\\b\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[27] = "27 1B 00011011 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bA\\b\\s*\\b\\+\\b\\s*\\bPC\\b 1".split(" ");
        mnemonicTable[28] = "28 1C 00011100 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*@\\s*(?!\\bA\\b|\\bDPTR\\b) 3".split(" ");
        mnemonicTable[29] = "29 1D 00011101 \\bMOV\\b\\s+@(?=\\w*,\\s*\\bA\\b)(?!\\bDPTR\\b) 3".split(" ");
        mnemonicTable[30] = "30 1E 00011110 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[31] = "31 1F 00011111 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bA\\b\\s* 1".split(" ");
        mnemonicTable[32] = "32 20 00100000 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bR0\\b\\s* 1".split(" ");
        mnemonicTable[33] = "33 21 00100001 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bR1\\b\\s* 1".split(" ");
        mnemonicTable[34] = "34 22 00100010 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bR2\\b\\s* 1".split(" ");
        mnemonicTable[35] = "35 23 00100011 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bR3\\b\\s* 1".split(" ");
        mnemonicTable[36] = "36 24 00100100 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bDPH\\b\\s* 1".split(" ");
        mnemonicTable[37] = "37 25 00100101 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bDPL\\b\\s* 1".split(" ");
        mnemonicTable[38] = "38 26 00100110 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bSPH\\b\\s* 1".split(" ");
        mnemonicTable[39] = "39 27 00100111 \\bMOV\\b\\s+@\\s*\\bDPTR\\b\\s*,\\s*\\bSPL\\b\\s* 1".split(" ");
        mnemonicTable[40] = "40 28 00101000 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[41] = "41 29 00101001 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[42] = "42 2A 00101010 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[43] = "43 2B 00101011 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[44] = "44 2C 00101100 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[45] = "45 2D 00101101 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[46] = "46 2E 00101110 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[47] = "47 2F 00101111 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[48] = "48 30 00110000 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*\\bA\\b 1".split(" ");
        mnemonicTable[49] = "49 31 00110001 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*\\bA\\b 1".split(" ");
        mnemonicTable[50] = "50 32 00110010 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*\\bA\\b 1".split(" ");
        mnemonicTable[51] = "51 33 00110011 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*\\bA\\b 1".split(" ");
        mnemonicTable[52] = "52 34 00110100 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*\\bA\\b 1".split(" ");
        mnemonicTable[53] = "53 35 00110101 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*\\bA\\b 1".split(" ");
        mnemonicTable[54] = "54 36 00110110 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*\\bA\\b 1".split(" ");
        mnemonicTable[55] = "55 37 00110111 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*\\bA\\b 1".split(" ");
        mnemonicTable[56] = "56 38 00111000 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[57] = "57 39 00111001 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[58] = "58 3A 00111010 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[59] = "59 3B 00111011 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[60] = "60 3C 00111100 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[61] = "61 3D 00111101 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[62] = "62 3E 00111110 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*\\bSPH\\b 1".split(" ");
        mnemonicTable[63] = "63 3F 00111111 \\bMOV\\b\\s+\\bA\\b\\s*,\\s*\\bSPL\\b 1".split(" ");
        mnemonicTable[64] = "64 40 01000000 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[65] = "65 41 01000001 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[66] = "66 42 01000010 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[67] = "67 43 01000011 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[68] = "68 44 01000100 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[69] = "69 45 01000101 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[70] = "70 46 01000110 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*\\bSPH\\b 1".split(" ");
        mnemonicTable[71] = "71 47 01000111 \\bMOV\\b\\s+\\bR0\\b\\s*,\\s*\\bSPL\\b 1".split(" ");
        mnemonicTable[72] = "72 48 01001000 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[73] = "73 49 01001001 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[74] = "74 4A 01001010 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[75] = "75 4B 01001011 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[76] = "76 4C 01001100 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[77] = "77 4D 01001101 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[78] = "78 4E 01001110 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*\\bSPH\\b 1".split(" ");
        mnemonicTable[79] = "79 4F 01001111 \\bMOV\\b\\s+\\bR1\\b\\s*,\\s*\\bSPL\\b 1".split(" ");
        mnemonicTable[80] = "80 50 01010000 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[81] = "81 51 01010001 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[82] = "82 52 01010010 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[83] = "83 53 01010011 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[84] = "84 54 01010100 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[85] = "85 55 01010101 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[86] = "86 56 01010110 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*\\bSPH\\b 1".split(" ");
        mnemonicTable[87] = "87 57 01010111 \\bMOV\\b\\s+\\bR2\\b\\s*,\\s*\\bSPL\\b 1".split(" ");
        mnemonicTable[88] = "88 58 01011000 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[89] = "89 59 01011001 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[90] = "90 5A 01011010 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[91] = "91 5B 01011011 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[92] = "92 5C 01011100 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[93] = "93 5D 01011101 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[94] = "94 5E 01011110 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*\\bSPH\\b 1".split(" ");
        mnemonicTable[95] = "95 5F 01011111 \\bMOV\\b\\s+\\bR3\\b\\s*,\\s*\\bSPL\\b 1".split(" ");
        mnemonicTable[96] = "96 60 01100000 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[97] = "97 61 01100001 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[98] = "98 62 01100010 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[99] = "99 63 01100011 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[100] = "100 64 01100100 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[101] = "101 65 01100101 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[102] = "102 66 01100110 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*\\bSPH\\b 1".split(" ");
        mnemonicTable[103] = "103 67 01100111 \\bMOV\\b\\s+\\bDPH\\b\\s*,\\s*\\bSPL\\b 1".split(" ");
        mnemonicTable[104] = "104 68 01101000 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[105] = "105 69 01101001 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[106] = "106 6A 01101010 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[107] = "107 6B 01101011 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[108] = "108 6C 01101100 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[109] = "109 6D 01101101 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[110] = "110 6E 01101110 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*\\bSPH\\b 1".split(" ");
        mnemonicTable[111] = "111 6F 01101111 \\bMOV\\b\\s+\\bDPL\\b\\s*,\\s*\\bSPL\\b 1".split(" ");
        mnemonicTable[112] = "112 70 01110000 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[113] = "113 71 01110001 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[114] = "114 72 01110010 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[115] = "115 73 01110011 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[116] = "116 74 01110100 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[117] = "117 75 01110101 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[118] = "118 76 01110110 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[119] = "119 77 01110111 \\bMOV\\b\\s+\\bSPH\\b\\s*,\\s*\\bSPL\\b 1".split(" ");
        mnemonicTable[120] = "120 78 01111000 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[121] = "121 79 01111001 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[122] = "122 7A 01111010 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[123] = "123 7B 01111011 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[124] = "124 7C 01111100 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[125] = "125 7D 01111101 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[126] = "126 7E 01111110 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*\\bSPH\\b 1".split(" ");
        mnemonicTable[127] = "127 7F 01111111 \\bMOV\\b\\s+\\bSPL\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[128] = "128 80 10000000 \\bANL\\b\\s+\\bA\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[129] = "129 81 10000001 \\bANL\\b\\s+\\bA\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[130] = "130 82 10000010 \\bANL\\b\\s+\\bA\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[131] = "131 83 10000011 \\bANL\\b\\s+\\bA\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[132] = "132 84 10000100 \\bANL\\b\\s+\\bA\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[133] = "133 85 10000101 \\bANL\\b\\s+\\bA\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[134] = "134 86 10000110 \\bANL\\b\\s+\\bA\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[135] = "135 87 10000111 \\bANL\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[136] = "136 88 10001000 \\bORL\\b\\s+\\bA\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[137] = "137 89 10001001 \\bORL\\b\\s+\\bA\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[138] = "138 8A 10001010 \\bORL\\b\\s+\\bA\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[139] = "139 8B 10001011 \\bORL\\b\\s+\\bA\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[140] = "140 8C 10001100 \\bORL\\b\\s+\\bA\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[141] = "141 8D 10001101 \\bORL\\b\\s+\\bA\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[142] = "142 8E 10001110 \\bORL\\b\\s+\\bA\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[143] = "143 8F 10001111 \\bORL\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[144] = "144 90 10010000 \\bXRL\\b\\s+\\bA\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[145] = "145 91 10010001 \\bXRL\\b\\s+\\bA\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[146] = "146 92 10010010 \\bXRL\\b\\s+\\bA\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[147] = "147 93 10010011 \\bXRL\\b\\s+\\bA\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[148] = "148 94 10010100 \\bXRL\\b\\s+\\bA\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[149] = "149 95 10010101 \\bXRL\\b\\s+\\bA\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[150] = "150 96 10010110 \\bXRL\\b\\s+\\bA\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[151] = "151 97 10010111 \\bXRL\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[152] = "152 98 10011000 \\bRL\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[153] = "153 99 10011001 \\bRLC\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[154] = "154 9A 10011010 \\bRR\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[155] = "155 9B 10011011 \\bRRC\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[156] = "156 9C 10011100 \\bINC\\b\\s+\\bDPTR\\b 1".split(" ");
        mnemonicTable[157] = "157 9D 10011101 \\bDEC\\b\\s+\\bDPTR\\b 1".split(" ");
        mnemonicTable[158] = "158 9E 10011110 \\bINC\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[159] = "159 9F 10011111 \\bDEC\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[160] = "160 A0 10100000 \\bADD\\b\\s+\\bA\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[161] = "161 A1 10100001 \\bADD\\b\\s+\\bA\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[162] = "162 A2 10100010 \\bADD\\b\\s+\\bA\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[163] = "163 A3 10100011 \\bADD\\b\\s+\\bA\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[164] = "164 A4 10100100 \\bADD\\b\\s+\\bA\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[165] = "165 A5 10100101 \\bADD\\b\\s+\\bA\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[166] = "166 A6 10100110 \\bADD\\b\\s+\\bA\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[167] = "167 A7 10100111 \\bADD\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[168] = "168 A8 10101000 \\bADDC\\b\\s+\\bA\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[169] = "169 A9 10101001 \\bADDC\\b\\s+\\bA\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[170] = "170 AA 10101010 \\bADDC\\b\\s+\\bA\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[171] = "171 AB 10101011 \\bADDC\\b\\s+\\bA\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[172] = "172 AC 10101100 \\bADDC\\b\\s+\\bA\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[173] = "173 AD 10101101 \\bADDC\\b\\s+\\bA\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[174] = "174 AE 10101110 \\bADDc\\b\\s+\\bA\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[175] = "175 AF 10101111 \\bADDC\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[176] = "176 B0 10110000 \\bSUB\\b\\s+\\bA\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[177] = "177 B1 10110001 \\bSUB\\b\\s+\\bA\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[178] = "178 B2 10110010 \\bSUB\\b\\s+\\bA\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[179] = "179 B3 10110011 \\bSUB\\b\\s+\\bA\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[180] = "180 B4 10110100 \\bSUB\\b\\s+\\bA\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[181] = "181 B5 10110101 \\bSUB\\b\\s+\\bA\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[182] = "182 B6 10110110 \\bSUB\\b\\s+\\bA\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[183] = "183 B7 10110111 \\bSUB\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[184] = "184 B8 10111000 \\bSUBB\\b\\s+\\bA\\b\\s*,\\s*\\bR0\\b 1".split(" ");
        mnemonicTable[185] = "185 B9 10111001 \\bSUBB\\b\\s+\\bA\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[186] = "186 BA 10111010 \\bSUBB\\b\\s+\\bA\\b\\s*,\\s*\\bR2\\b 1".split(" ");
        mnemonicTable[187] = "187 BB 10111011 \\bSUBB\\b\\s+\\bA\\b\\s*,\\s*\\bR3\\b 1".split(" ");
        mnemonicTable[188] = "188 BC 10111100 \\bSUBB\\b\\s+\\bA\\b\\s*,\\s*\\bDPH\\b 1".split(" ");
        mnemonicTable[189] = "189 BD 10111101 \\bSUBB\\b\\s+\\bA\\b\\s*,\\s*\\bDPL\\b 1".split(" ");
        mnemonicTable[190] = "190 BE 10111110 \\bSUBB\\b\\s+\\bA\\b\\s*,\\s*#\\s* 2".split(" ");
        mnemonicTable[191] = "191 BF 10111111 \\bSUBB\\b\\s+\\bA\\b\\s*,\\s*@\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[192] = "192 C0 11000000 \\bPJMP\\b\\s+\\b00 2".split(" ");
        mnemonicTable[193] = "193 C1 11000001 \\bPJMP\\b\\s+\\b01 2".split(" ");
        mnemonicTable[194] = "194 C2 11000010 \\bPJMP\\b\\s+\\b02 2".split(" ");
        mnemonicTable[195] = "195 C3 11000011 \\bPJMP\\b\\s+\\b03 2".split(" ");
        mnemonicTable[196] = "196 C4 11000100 \\bPJMP\\b\\s+\\b04 2".split(" ");
        mnemonicTable[197] = "197 C5 11000101 \\bPJMP\\b\\s+\\b05 2".split(" ");
        mnemonicTable[198] = "198 C6 11000110 \\bPJMP\\b\\s+\\b06 2".split(" ");
        mnemonicTable[199] = "199 C7 11000111 \\bPJMP\\b\\s+\\b07 2".split(" ");
        mnemonicTable[200] = "200 C8 11001000 \\bPCALL\\b\\s+\\b00 2".split(" ");
        mnemonicTable[201] = "201 C9 11001001 \\bPCALL\\b\\s+\\b01 2".split(" ");
        mnemonicTable[202] = "202 CA 11001010 \\bPCALL\\b\\s+\\b02 2".split(" ");
        mnemonicTable[203] = "203 CB 11001011 \\bPCALL\\b\\s+\\b03 2".split(" ");
        mnemonicTable[204] = "204 CC 11001100 \\bPCALL\\b\\s+\\b04 2".split(" ");
        mnemonicTable[205] = "205 CD 11001101 \\bPCALL\\b\\s+\\b05 2".split(" ");
        mnemonicTable[206] = "206 CE 11001110 \\bPCALL\\b\\s+\\b06 2".split(" ");
        mnemonicTable[207] = "207 CF 11001111 \\bPCALL\\b\\s+\\b07 2".split(" ");
        mnemonicTable[208] = "208 D0 11010000 \\bDJNZ\\b\\s+\\bR0\\b\\s*,\\s* 2".split(" ");
        mnemonicTable[209] = "209 D1 11010001 \\bDJNZ\\b\\s+\\bR1\\b\\s*,\\s* 2".split(" ");
        mnemonicTable[210] = "210 D2 11010010 \\bDJNZ\\b\\s+\\bR2\\b\\s*,\\s* 2".split(" ");
        mnemonicTable[211] = "211 D3 11010011 \\bDJNZ\\b\\s+\\bR3\\b\\s*,\\s* 2".split(" ");
        mnemonicTable[212] = "212 D4 11010100 \\bCJNE\\b\\s+\\bR0\\b\\s*,\\s*# 3".split(" ");
        mnemonicTable[213] = "213 D5 11010101 \\bCJNE\\b\\s+\\bR1\\b\\s*,\\s*# 3".split(" ");
        mnemonicTable[214] = "214 D6 11010110 \\bCJNE\\b\\s+\\bR2\\b\\s*,\\s*# 3".split(" ");
        mnemonicTable[215] = "215 D7 11010111 \\bCJNE\\b\\s+\\bR3\\b\\s*,\\s*# 3".split(" ");
        mnemonicTable[216] = "216 D8 11011000 \\bLJMP\\b\\s+ 3".split(" ");
        mnemonicTable[217] = "217 D9 11011001 \\bLCALL\\b\\s+ 3".split(" ");
        mnemonicTable[218] = "218 DA 11011010 \\bRET\\b 1".split(" ");
        mnemonicTable[219] = "219 DB 11011011 \\bRETI\\b 1".split(" ");
        mnemonicTable[220] = "220 DC 11011100 \\bSJMP\\b\\s+ 2".split(" ");
        mnemonicTable[221] = "221 DD 11011101 \\bJMP\\b\\s+@\\s*\\bA\\b\\s*\\b\\+\\b\\s*\\bDPTR\\b 1".split(" ");
        mnemonicTable[222] = "222 DE 11011110 \\bJMP\\b\\s+@\\bDPTR\\b 1".split(" ");
        mnemonicTable[223] = "223 DF 11011111 \\bCJNE\\b\\s+\\bA\\b\\s*,\\s*# 3".split(" ");
        mnemonicTable[224] = "224 E0 11100000 \\bJZ\\b\\s+ 2".split(" ");
        mnemonicTable[225] = "225 E1 11100001 \\bJNZ\\b\\s+ 2".split(" ");
        mnemonicTable[226] = "226 E2 11100010 \\bJC\\b\\s+ 2".split(" ");
        mnemonicTable[227] = "227 E3 11100011 \\bJNC\\b\\s+ 2".split(" ");
        mnemonicTable[228] = "228 E4 11100100 \\bJPO\\b\\s+ 2".split(" ");
        mnemonicTable[229] = "229 E5 11100101 \\bJPE\\b\\s+ 2".split(" ");
        mnemonicTable[230] = "230 E6 11100110 \\bJS\\b\\s+ 2".split(" ");
        mnemonicTable[231] = "231 E7 11100111 \\bJNS\\b\\s+ 2".split(" ");
        mnemonicTable[232] = "232 E8 11101000 \\bPUSH\\b\\s+\\bR0\\b 1".split(" ");
        mnemonicTable[233] = "233 E9 11101001 \\bPUSH\\b\\s+\\bR1\\b 1".split(" ");
        mnemonicTable[234] = "234 EA 11101010 \\bPUSH\\b\\s+\\bR2\\b 1".split(" ");
        mnemonicTable[235] = "235 EB 11101011 \\bPUSH\\b\\s+\\bR3\\b 1".split(" ");
        mnemonicTable[236] = "236 EC 11101100 \\bPUSH\\b\\s+\\bDPH\\b 1".split(" ");
        mnemonicTable[237] = "237 ED 11101101 \\bPUSH\\b\\s+\\bDPL\\b 1".split(" ");
        mnemonicTable[238] = "238 EE 11101110 \\bPUSH\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[239] = "239 EF 11101111 \\bPUSH\\b\\s+\\bFLAGS\\b 1".split(" ");
        mnemonicTable[240] = "240 F0 11110000 \\bPOP\\b\\s+\\bR0\\b 1".split(" ");
        mnemonicTable[241] = "241 F1 11110001 \\bPOP\\b\\s+\\bR1\\b 1".split(" ");
        mnemonicTable[242] = "242 F2 11110010 \\bPOP\\b\\s+\\bR2\\b 1".split(" ");
        mnemonicTable[243] = "243 F3 11110011 \\bPOP\\b\\s+\\bR3\\b 1".split(" ");
        mnemonicTable[244] = "244 F4 11110100 \\bPOP\\b\\s+\\bDPH\\b 1".split(" ");
        mnemonicTable[245] = "245 F5 11110101 \\bPOP\\b\\s+\\bDPL\\b 1".split(" ");
        mnemonicTable[246] = "246 F6 11110110 \\bPOP\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[247] = "247 F7 11110111 \\bPOP\\b\\s+\\bFLAGS\\b 1".split(" ");
        mnemonicTable[248] = "248 F8 11111000 \\bMUL\\b\\s+\\bR0\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[249] = "249 F9 11111001 \\bDIV\\b\\s+\\bR0\\b\\s*,\\s*\\bR1\\b 1".split(" ");
        mnemonicTable[250] = "250 FA 11111010 \\bDA\\b\\s+\\bA\\b 1".split(" ");
        mnemonicTable[251] = "251 FB 11111011 \\breserved\\b 0".split(" ");
        mnemonicTable[252] = "252 FC 11111100 \\bIN\\b\\s+\\bA\\b\\s*,\\s* 2".split(" ");
        mnemonicTable[253] = "253 FD 11111101 \\bOUT\\b\\s+ 2".split(" ");
        mnemonicTable[254] = "254 FE 11111110 \\bINT\\b\\s+ 2".split(" ");
        mnemonicTable[255] = "255 FF 11111111 \\bHLT\\b 1".split(" ");
    }

    private String mnemonicTable[][] = new String[256][10];

}
